package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminSetmealController")
@Slf4j
@RequestMapping("/admin/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 新增套餐
     * @param setmealDTO
     * @return
     */
    @PostMapping()
    @CacheEvict
    public Result addSetmeal(@RequestBody SetmealDTO setmealDTO){
        return setmealService.addSetmeal(setmealDTO);
    }

    /**
     * 分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result page(SetmealPageQueryDTO setmealPageQueryDTO){
        return setmealService.page(setmealPageQueryDTO);
    }

    /**
     * 批量删除套餐
     * @param ids
     * @return
     */
    @DeleteMapping
    @CacheEvict
    public Result delectSetmeal(@RequestParam List<Long> ids){
        return setmealService.delectSetmeal(ids);
    }

    /**
     * 修改套餐
     * @param setmealDTO
     * @return
     */
    @PutMapping
    @CacheEvict
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO){
        return setmealService.updateSetmeal(setmealDTO);
    }

    /**
     * 根据id回显数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result selectId(@PathVariable Long id){
        return setmealService.selectId(id);
    }

    /**
     * 起售停售
     * @param status
     * @return
     */
    @PostMapping("/status/{status}")
    @CacheEvict
    public Result status(@PathVariable Integer status,Long id){
        return setmealService.status(status,id);
    }
}
